package com.lzhpo.common.util;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName ListsUtils
 * @Description: TODO
 * @Author lijin
 * @Date 2020/8/29
 * @Author 740393778@qq.com
 * @Version V1.0
 **/
public class ListsUtils {


    /**
     * 求出集合中最小的n个数所在的下标
     */
    public static List<Integer> minNumberIndexOfList(List<Integer> list,int n){
        List<Integer> sortedLists= list.stream().sorted().collect(Collectors.toList());
        //最小的n个数
        sortedLists=sortedLists.stream().skip(0).limit(n).collect(Collectors.toList());
        List<Integer> res = new ArrayList<>();
        for (int i = 0; i < sortedLists.size(); i++) {
            Integer e=sortedLists.get(i);
            int index=list.indexOf(e);
            res.add(index);
            list.set(index,-1);
        }
        return  res;
    }

}
